//网络 请求
import config from './config'
import { fail } from 'assert';

 export default function post(url,deta,type){
    console.log("333");
    wx.showLoading({
        title: '加载中....',
    })

     return new Promise((reslove)=>{
        console.log("======4444444999999=====");
        console.log(url);
        console.log(deta);
        console.log(config.host);
        var reauestAddress=config.host;
        var requestHeader="application/x-www-form-urlencoded";
        if(type=="work"){
            reauestAddress=config.hostWork;
            requestHeader="";
        }else{
            reauestAddress=config.host;
            requestHeader="application/x-www-form-urlencoded";
        }

        console.log("requestHeader========",requestHeader);


        wx.request({
            data:deta,
            url:reauestAddress+url,
            method:"post",
            // application/json
            header:{"Content-type":requestHeader},
            success:function(res){
                wx.hideLoading()
                console.log("===========");
                console.log(res);
                // reslove(res)
                if(res.data.returnCode==1|| res.data.returnCode==2){
                    reslove(res)
                }else{
                    let msg="网络请求出错";
                    if(res.data.returnMessage){
                        msg=res.data.returnMessage
                    }
                    wx.showToast({
                        title:msg,
                        icon: "none",
                        duration: 4000
                      });
                      reslove(res);
                }
            },
            fail:function(err){
                wx.hideLoading()
                let res={
                     data:{
                         returnCode:0,
                          returnMessage:"网络请求错误",
                      }
                }
                wx.showToast({
                    title: res.data.returnMessage,
                    icon: "none",
                    duration: 3000
                  });
                  reslove(res);
            },//请求失败
            complete:function(){
                wx.hideLoading()
            }//请求完成后执行的函数
           
        })
        // wx.hideLoading()
     })
 }


